package com.dctp.ems.controller.chart;

import com.dctp.common.db.FxRateDb;
import com.jfinal.plugin.activerecord.Record;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class ChartQueryManager {

    private static final Map<String, ChartQuery> chartQueryMap = new HashMap<>();

    static {

    }


    public static void init() {
        // key: 统计类型
        chartQueryMap.put("1", new ChartQuery("dctp_user", "count(id)", "create_time", null, null, null)); // 注册人数
        chartQueryMap.put("2", new ChartQuery("dctp_recharge", "sum(amount)", "audit_time", null, "audit_status", 1)); // 充值
        chartQueryMap.put("3", new ChartQuery("dctp_withdraw", "sum(amount_from)", "audit_time", null, "audit_status", 1)); // 提现
        chartQueryMap.put("4", new ChartQuery("dctp_transfer", "sum(amount)", "create_time", null, "status", 1)); // 转账
        chartQueryMap.put("5", new ChartQuery("dctp_order", "sum(realized_pnl)", "close_time", "symbol", "status", 2)); // 平仓盈亏
        chartQueryMap.put("6", new ChartQuery("dctp_order", "count(id)", "create_time", "symbol", "status", 1)); // 持仓人数
        chartQueryMap.put("7", new ChartQuery("dctp_order", "sum(quantity)", "create_time", "symbol", "status", 1)); // 持仓手数
        chartQueryMap.put("8", new ChartQuery("dctp_order", "sum(open_service_fee + ifnull(close_service_fee,0))", "close_time", "symbol", "status", 2)); // 服务费
        chartQueryMap.put("9", new ChartQuery("dctp_fund_flow", "sum(change_amount)", "create_time", "null", "change_type", 12)); // 额度变更
        chartQueryMap.put("10", new ChartQuery("dctp_commission_record", "sum(fr_amount)", "create_time", null, null, null)); // 佣金
        chartQueryMap.put("11", new ChartQuery("dctp_user", "sum(balance2)", "create_time", "null", null, null)); // 1:1额度

    }

    public static ChartQuery get(String key) {
        return chartQueryMap.get(key);
    }

    public static class ChartQuery {
        /** 统计表名 */
        public String tableName;
        /** 统计字段 */
        public String statField;
        /** 分组/日期字段 */
        public String dateField;
        /** 分组字段 */
        public String symbolField;
        /** 过滤字段 */
        public String filterField;
        /** 过滤值 */
        public Integer filterValue;


        public ChartQuery(String tableName, String statField, String dateField, String symbolField, String filterField, Integer filterValue) {
            this.tableName = tableName;
            this.statField = statField;
            this.dateField = dateField;
            this.symbolField = symbolField;
            this.filterField = filterField;
            this.filterValue = filterValue;
        }
    }
}
